package com.csw.monkmanager.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 1
 */
@Configuration
public class  EsConfig{
    @Value("${spring.elasticsearch.rest.uris}")
    private String esUrl;

 /**   localhost:9200 写在配置文件中就可以了*/
    @Bean
    RestHighLevelClient client() throws IOException {
       /* elasticsearch地址*/
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(esUrl)
                .build();

        try(RestHighLevelClient rest = RestClients.create(clientConfiguration).rest();){
            return rest;
        }

    }
}
